﻿
namespace HSS.Xaml.UI.Controls
{
	#region Using Directives
	using System.Windows;
	using System.Windows.Controls;
	using HSS.ComponentModel;
	using HSS.Xaml.UI.Data;
	#endregion

	#region EnumFlagValueEditor
	/// <summary>
	/// A special value editor for <see cref="System.Enum"/>'s that are marked with the <see cref="System.FlagsAttribute"/> attribute.
	/// </summary>
	[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Flag")]
	public class EnumFlagValueEditor : AutoCompleteBoxEditorBase
	{
		#region Constructors
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="descriptor">The HSSPropertyDescriptor being viewed</param>
		public EnumFlagValueEditor(HSSPropertyDescriptor descriptor)
			: base(descriptor)
		{
		}
		#endregion

		/// <summary>
		/// Gets a collection of the Enum items.
		/// </summary>
		/// <returns>An object collection of Enum items.</returns>
		protected override System.Collections.Generic.IEnumerable<object> GetListItems()
		{
			return EnumHelper.GetValues(Descriptor.PropertyType);
		}
		/// <summary>
		/// Creates the InLineEdit Control for this editor.
		/// </summary>
		/// <returns>An <see cref="AutoCompleteComboBox"/>.</returns>
		protected override FrameworkElement CreateInlineEditControl()
		{
			var box = (AutoCompleteComboBox)base.CreateInlineEditControl();
			box.ValueMemberBinding = new System.Windows.Data.Binding("ObjectValue")
				{
					Converter = new EnumValueConverter()
				};
			box.IsTextCompletionEnabled = false;
			box.MinimumPrefixLength = 0;
			box.MinimumPopulateDelay = 0;
			box.FilterMode = AutoCompleteFilterMode.None;
			return box;
		}
		/// <summary>
		/// Gets the Controls value.
		/// </summary>
		/// <returns>The Controls value object.</returns>
		protected override object GetControlValue()
		{
			return this.Control.Text;
		}
	}
	#endregion
}